//
//  MNDConfirmInvestAlertViewController.m
//  minidai
//
//  Created by Vitas on 2018/7/14.
//  Copyright © 2018年 迷你贷. All rights reserved.
//

#import "MNDConfirmInvestAlertViewController.h"
#import <TTTAttributedLabel/TTTAttributedLabel.h>
#import "MNDWebViewController.h"

@interface MNDConfirmInvestAlertViewController ()<TTTAttributedLabelDelegate>

@property (weak, nonatomic) IBOutlet TTTAttributedLabel *protocolLabel;
@property (weak, nonatomic) IBOutlet UILabel *inventMoneyLabel;
@property (weak, nonatomic) IBOutlet UILabel *amountLabel;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *confirmButtonBottomMargin;
@property (weak, nonatomic) IBOutlet UILabel *amountPayMoney;

@end

@implementation MNDConfirmInvestAlertViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.confirmButton.layer.cornerRadius = self.confirmButton.bounds.size.height*0.5;
    self.confirmButton.clipsToBounds = YES;
    
    self.inventMoneyLabel.text = [NSString stringWithFormat:@"%@元",self.moneyStr];
    self.amountPayMoney.text = self.moneyStr;
    self.amountLabel.text = [NSString stringWithFormat:@"当前账户余额%@元",self.amountStr];
    
    if (kScreenHeight >= 812) {
        self.confirmButtonBottomMargin.constant = 88;
    } else {
         self.confirmButtonBottomMargin.constant = 64;
    }
//    self.alertContainView.frame = CGRectMake(self.alertContainView.frame.origin.x, kScreenHeight, self.alertContainView.frame.size.width, self.alertContainView.frame.size.height);
    
    //设置高亮颜色
    self.protocolLabel.highlightedTextColor = kColorOrange;
    //检测类型
    self.protocolLabel.enabledTextCheckingTypes = NSTextCheckingTypeLink;
    //代理
    self.protocolLabel.delegate = self;
    //不显示下划线
    self.protocolLabel.linkAttributes = @{(NSString *)kCTUnderlineStyleAttributeName: [NSNumber numberWithBool:NO]};
    NSString *text = @"点击确认即同意《江西银行网络交易资金账户服务三方协议》";
    
    [self.protocolLabel setText:text afterInheritingLabelAttributesAndConfiguringWithBlock:^NSMutableAttributedString *(NSMutableAttributedString *mutableAttributedString) {
        NSRange linkRange = [[mutableAttributedString string] rangeOfString:@"《江西银行网络交易资金账户服务三方协议》" options:NSCaseInsensitiveSearch];
      
        [mutableAttributedString addAttributes:@{(NSString *)kCTForegroundColorAttributeName: kColorOrange} range:linkRange];
        
        return mutableAttributedString;
    }];
    NSRange linkRange = [text rangeOfString:@"《江西银行网络交易资金账户服务三方协议》" options:NSCaseInsensitiveSearch];
    NSURL *url = [NSURL URLWithString:kBank_Service_Protocol];
    [self.protocolLabel addLinkToURL:url withRange:linkRange];
    // Do any additional setup after loading the view.
}


- (void)attributedLabel:(TTTAttributedLabel *)label didSelectLinkWithURL:(NSURL *)url {
    MNDWebViewController *webVC = [[MNDWebViewController alloc] init];
    webVC.webViewUrl = url.absoluteString;
    webVC.loadType = LoadTypeLink;
    webVC.naviBarHidden = NO;
    webVC.title = @"江西银行网络交易资金账户服务三方协议";
    UINavigationController *navVC = [[UINavigationController alloc] initWithRootViewController:webVC];
    
    [self presentViewController:navVC animated:YES completion:^{
        
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
